home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / doors / window / window.c next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  3.7 KB  |  175 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "work:romconf/doorheader.h"
  5. #define ACCESS_WRITE -1
  6.  
  7. /****** AmiExpress now will return arrow key information as the following
  8.         codes, these codes are stored as the first character in any
  9.         getuserstring function
  10.  ******/
  11. #define sm sendmessage
  12. #define cm sendchar
  13. #define pu putuserstring
  14. #define co ConOnly
  15. #define fk Fhotkey
  16.  
  17. #define RIGHTARROW 3
  18. #define LEFTARROW 2
  19. #define UPARROW 4
  20. #define DOWNARROW 5
  21.  
  22. #define gu getuserstring
  23. #define pu putuserstring
  24. void Goto(int x,int y); /* Used to position cursor at specific locations
  25.                            on the screen
  26.                         */
  27. void sr(char *str); /* removes trailing ascii codes < 33 from any string */
  28.  
  29. void LastCommand(void);
  30. void Editor(int leftedge, int topedge,int width,int height);
  31. void LoadView(char *filename,int leftedge,int topedge,int width,int height);
  32. void end(void);
  33. void Record(int x,int y);
  34. char *viewsize=NULL;
  35. long visual=0L;
  36. main(int argc,char *argv[])
  37. {
  38.   if(argc!=2)
  39.   {
  40.     printf("Window version 1.0, written by Joseph Hodge\n");
  41.     printf("\n");
  42.     exit(0);
  43.   }
  44.   Register(argv[1][0]-'0');
  45.   LoadView("ram:temp",1,10,80,9);
  46.   
  47.   Editor(34,10,44,9);
  48.  
  49. }
  50.  
  51. void LastCommand(void)
  52. {
  53.   sm("",1); sm("",1);
  54.   if(viewsize) FreeMem(viewsize,visual);
  55. }
  56. void end(void)
  57. {
  58.    exit(0);
  59. }
  60. void LoadView(char *filename,int leftedge,int topedge,int width,int height)
  61. {
  62.    
  63.    register int i=0;
  64.    char temp[2];
  65.    int minwidth=0;
  66.    int lines=0;
  67.    FILE *fi;
  68.    temp[1]='\0';
  69.    viewsize=(char *)AllocMem(width*height,MEMF_CLEAR|MEMF_PUBLIC);
  70.    visual=width*height;
  71.    if(viewsize==NULL)
  72.    {
  73.      ShutDown(); end();
  74.    }
  75.    sm("H",0);
  76.    Goto(leftedge,topedge);
  77.    fi=fopen(filename,"rb");
  78.    if(fi!=NULL)
  79.    {
  80.       while(fread((APTR)&temp[0],sizeof(char),1,fi)!=NULL)
  81.       {
  82.         if(temp[0]==13 || temp[0]==12 || temp[0]==10){ 
  83.           while(minwidth<width && i<visual) { *(viewsize+i)=' '; i++; minwidth++;} minwidth=0;
  84.            lines++; Goto(leftedge,topedge+lines); }
  85.         else 
  86.         { 
  87.           if(temp[0]!=EOF && i<visual)
  88.           { 
  89.             *(viewsize+i)=temp[0]; i++; minwidth++; 
  90.             sm(temp,0); 
  91.           }
  92.         }
  93.       }
  94.       fclose(fi);
  95.  
  96.    }
  97.    while(i<width*height) { *(viewsize+i)=' '; i++; }
  98. }
  99.  
  100. void Editor(int leftedge,int topedge,int width,int height)
  101. {
  102.   char temp[10];
  103.   int hmd;
  104.   int x=leftedge,y=topedge;
  105.  pu("",RAWARROW); /** Turns off arrowkey filter, allowing us to
  106.                          intercept them and do what we wish with it
  107.                       **/
  108.  
  109.   
  110.   Goto(x,y);
  111.  do
  112.   {
  113.      hotkey("",temp);hmd=temp[0];
  114.      //hmd=Fhotkey();
  115.      switch(hmd)
  116.      {
  117.        case RIGHTARROW:
  118.              if(x+1<=leftedge+width)
  119.              {
  120.               x++;
  121.               sm("C",0);
  122.              }   
  123.              break;
  124.        case LEFTARROW:
  125.              if(x-1>=leftedge)
  126.              { x--;
  127.               sm("D",0); 
  128.              }
  129.              break;
  130.        case UPARROW:
  131.             if(y-1>=topedge) 
  132.             {
  133.               y--;
  134.               sm("A",0);
  135.             }
  136.             break;
  137.        case DOWNARROW:
  138.             if(y+1<=topedge+height)
  139.             {
  140.               y++;
  141.               sm("B",0);
  142.             }
  143.             break;
  144.        case 12:
  145.        case 13:
  146.             ShutDown();
  147.             end();
  148.             break;
  149.        case '\b':
  150.             if(x-1>=leftedge)
  151.             {
  152.               sm("\b \b",0);
  153.               x--;
  154.             } break;
  155.        default: 
  156.             if(x+1<=leftedge+width)
  157.             { 
  158.               sm(temp,0);
  159.               x++;
  160.               Record(x,y);
  161.             }
  162.      }
  163.   }while(1);
  164.   
  165. }
  166. void Goto(int x,int y)
  167. {
  168.   char local[20];
  169.   sprintf(local,"%d;%dH",y,x);
  170.   sm(local,0);
  171. }
  172.  
  173. void Record(int x,int y)
  174. {
  175. }